package logic

import (
	"context"

	"go-weixin/app/mqueue/order/internal/svc"
	"go-weixin/app/mqueue/order/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderLogic {
	return &OrderLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *OrderLogic) Order(req *types.Request) (resp *types.Response, err error) {
	err = l.Consumer()
	if err != nil {
		return nil, err
	}
	resp = new(types.Response)
	resp.Message = "启动延时任务成功"
	return
}

func (l *OrderLogic) Consumer() error {
	l.svcCtx.DqConsumer.Consume(func(body []byte) {
		logx.Infof("延时任务: job  %s \n", string(body))
	})
	return nil
}
